package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/**
 * this class is Graphic user interface of Sales Report, which extends AbstractGUI
 * @author jacob
 *
 */
public class SalesReportGui extends AbstractGUI {
/***all the buttons**/
	private JButton nextBu = null;
	private JButton backBSalesReport;
	/***all the label**/
	private JLabel lbtextSale = null;
	private JLabel lbwarningMas = null;
	/**combo box of sales*/
	private JComboBox salesCombo = null;
	/***the first panel is that one we need to choose some camping number **/
	private JPanel ChoosePanel ;
	/**the second panel is the sales report panel*/
	private JPanel SalesReportPanel ;
	private JScrollPane scroller;
	private JTextArea textArea;
	private Font myFont;
	private String str = "";
	/**
	 * constructor 
	 * this constructor add all the Label, Button,TextField,panel,ComboBox on the Frame
	 */
	public SalesReportGui(){
		super();
		backBSalesReport = new JButton("back to Menu");
		backBSalesReport.setBounds(70, 225, 100, 22);
		//create new panels
		ChoosePanel = new JPanel();
		SalesReportPanel =  new JPanel();
		initChoose();
		//initSalesRep();

	}
	
	/**
	 * Initialize the frame Bounds
	 */
	public void initChoose() {
		setTitle(" Choose sales ");
		setBounds(500, 200, 320, 330);
		//setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setSize(320, 330);
		setContentPane(getChoosePane());	
	}
	/**
	 * Initialize the sales report JTextArea,font 
	 * set the size of this sales panel
	 */
	public void initSalesRep() {
		textArea = new JTextArea("report",23,38);
		textArea.setFont(myFont = new Font("Serif",Font.BOLD,14));
		textArea.setEditable(false);
		setTitle(" Sales report ");
		//setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setSize(getMaximumSize());
		setContentPane(getSalesReport());	
	}
/**
 * get sales report panel and Initialize JScrollPane
 * set size of this panel
 * set visible of this panel to true
 * @return JPanel
 */
	public JPanel getSalesReport(){
		setLayout(null);
        textArea.setText(str);
        if(scroller == null){
        scroller = new JScrollPane(textArea);
        SalesReportPanel.add(scroller);
        SalesReportPanel.add(getbackBSalesRepurt());
        SalesReportPanel.setBackground(Color.lightGray);
        }
        setSize(500, 600);
       setLocationRelativeTo ( null );
        setVisible(true);
     return SalesReportPanel;
	}
	/**
	 * set Sales Report
	 */
	public void setSalesRep(){
		if(SalesReportPanel!=null)
		   setContentPane(SalesReportPanel);
        setLocationRelativeTo ( null );
        setVisible(true);
	}
	/**
	 *  get choose panel and add all the  buttons, combo box and labels
	 *  set color of panel
	 *  set Background color and Bounds of panel
	 * @return JPanel
	 */
	public JPanel getChoosePane(){
		ChoosePanel.setLayout(null);
		ChoosePanel.add(getNextBu());
		ChoosePanel.add(getSalesCombo());
		ChoosePanel.add(getbackBu());
		ChoosePanel.add(getLbtextSale());
		ChoosePanel.setBackground(Color.lightGray);
		ChoosePanel.setBounds(500, 200, 300, 250);
		
		setVisible(true);
		return ChoosePanel;
	}
	
	/*****************************************Getters and Setters of Labels, Buttons,TextFields,combo Box and panels *****************************/
	public JButton getbackBSalesRepurt() {		
		return backBSalesReport;
	}

	public JComboBox getSalesCombo() {
		if(salesCombo == null){
			salesCombo = new JComboBox();
			salesCombo.setBounds(120, 30, 160, 20);
		}
		return salesCombo;
	}
/**
 * get Next Buttom
 * @return JButton
 */
	public JButton getNextBu() {
		if(nextBu == null){
			nextBu = new JButton("next");
			nextBu.setBounds(170, 220, 100, 22);
		}		
		return nextBu;
	}
	/**
	 * get back Button
	 * @return JButton
	 */
	public JButton getbackBu() {
		if(backButton == null){
			backButton = new JButton("back");
			backButton.setBounds(30, 220, 100, 22);
		}		
		return backButton;
	}
/**
 * get label of marketing sales
 * @return JLabel
 */
	public JLabel getLbtextSale() {
		if(lbtextSale == null){
			lbtextSale = new JLabel("marketing sales: ");
			lbtextSale.setBounds(10, 28, 100, 22);
		}
		return lbtextSale;
	}
	/**
	 * get label of warning masage 
	 * @return JLabel
	 */
	public JLabel getLbwarningMas() {
		if(lbwarningMas == null){
			lbwarningMas = new JLabel("No activate campaign");
			lbwarningMas.setBounds(15, 150, 120, 22);
		}
		lbwarningMas.setVisible(false);
	return	lbwarningMas;
	}
	/**
	 * set warning massage to gui
	 */
	public void setWarnningMTrue(){
		lbwarningMas.setVisible(true);
	}
	/**
	 * dont show  warning massage on gui
	 */
	public void setWarnningMfalse(){
		lbwarningMas.setVisible(false);
	}
	public String getStr() { 
		return str;
	}
/**
 * set the text that you get from DB 
 * @param str1
 */
	public void setStr(String str1) {  
		this.str = str1;
	}
	public JTextArea getTextArea() {
		return textArea;
	}
	public JPanel getChoosePanel() {
		return ChoosePanel;
	}

	public void setChoosePanel(JPanel choosePanel) {
		ChoosePanel = choosePanel;
	}
	public JPanel getSalesReportPanel() {
		return SalesReportPanel;
	}

	public void setSalesReportPanel(JPanel salesReportPanel) {
		SalesReportPanel = salesReportPanel;
	}


	public void setTextArea(JTextArea textArea) {
		this.textArea = textArea;
	}
	
	/********************************************add to all buttons ActionListener ******************************************/
	
	public void addBackBottonSalesreportActionListener(ActionListener listener){
		backBSalesReport.addActionListener(listener);

	} 
	public void addNextBottonActionListener(ActionListener listener){
		nextBu.addActionListener(listener);

	} 
	
	public void addIdSalesActionListener(ItemListener listener){
		salesCombo.addItemListener(listener);
	}
	
}
